<template>
  <div class="list_container">
    <ul>
      <li v-for="(item, index) in list" :key="index">
        <img :src="item.author.avatar_url" alt="" />
        <p>{{ item.title }}</p>
        <span>{{ item.create_at | filterTime }}</span>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  props: ["list"],
  filters: {
    filterTime(value) {
      var newTime = new Date();
      var oldTime = new Date(value);
      var Time = parseInt((newTime - oldTime) / 1000);
      if (Time > 60 * 60 * 24) {
        return parseInt(Time / 60 / 60 / 24) + `天前`;
      } else if (Time > 60 * 60 && Time <= 60 * 60 * 24) {
        return parseInt(Time / 60 / 60) + `小时前`;
      } else if (Time > 60 && Time <= 60 * 60) {
        return parseInt(Time / 60) + `分钟前`;
      } else if (Time <= 60) {
        return `刚刚`;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.list_container {
  width: 100%;
  height: 100%;
  ul {
    width: 100%;
    li {
      width: 100%;
      height: 1rem;
      border: 1px solid gainsboro;
      box-sizing: border-box;
      padding: 0 0.2rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      img {
        width: 0.8rem;
        height: 0.8rem;
      }
      p {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        flex: 1;
        margin: 0 0.2rem;
      }
      span {
        font-size: 0.2rem;
        color: gray;
        display: flex;
        justify-content: center;
        align-items: center;
        width: 1.2rem;
      }
    }
  }
}
</style>